package com.guan.ordering_sys.generator.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guan.ordering_sys.common.PageResult;
import com.guan.ordering_sys.common.ResultApi;
import com.guan.ordering_sys.common.StateCode;
import com.guan.ordering_sys.generator.service.DeskService;
import com.guan.ordering_sys.param.DeskParam;
import com.guan.ordering_sys.vo.DeskVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 许少萍
 * @since 2021-06-23
 */
@Api(tags = "餐桌控制器")
@RestController
@RequestMapping("/api/desk")
public class DeskController {

    @Autowired
    DeskService deskService;


    /**
     * 列表
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "列表")
    @PostMapping("/list")
    public ResultApi List(@ApiParam("当前页") @RequestParam(required = true) int pageNum,
                          @ApiParam("页面大小") @RequestParam(required = true) int pageSize) {
        Page<DeskVo> deskVoPage = new Page<>();
        deskVoPage.setCurrent(pageNum);
        deskVoPage.setSize(pageSize);

        IPage<DeskVo> deskVoIPage = deskService.orderList(deskVoPage);
        PageResult<DeskVo> deskVoPageResult = new PageResult<>(deskVoIPage.getRecords().size(), deskVoIPage.getRecords());
        return ResultApi.success(deskVoPageResult);
    }

    /**
     * 修改审核状态
     * @param deskParam
     * @return
     */
    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public ResultApi update(@ApiParam("...")@RequestBody  DeskParam deskParam){
        if (deskService.update(deskParam) == 1) {
            return ResultApi.successDone(StateCode.getApiCode(200));
        } else {
            return ResultApi.errorNotData(StateCode.getApiCode(500));
        }
    }

}

